﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace OracleExpHelper
{
    public static class FormExts
    {

        /// <summary>
        /// 判断一个返回结果是否成功。如果失败，将会弹出异常信息。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="result">返回结果。</param>
        /// <returns>返回结果的状态。</returns>
        public static bool IsSuccess(this Control owner, IResult result)
        {
            return FormExts.IsSuccess(owner, result, string.Empty);
        }

        /// <summary>
        /// 判断一个返回结果是否成功。如果失败，将会弹出异常信息。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="result">返回结果。</param>
        /// <param name="other">其他信息。</param>
        /// <returns>返回结果的状态。</returns>
        public static bool IsSuccess(this Control owner, IResult result, string other)
        {
            if(result != null && !result.IsIgnored)
            {
                if(result.IsSucceed) return true;
                MessageBox.Show(owner, result.ToString() + other, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return false;
        }

    }
}
